package leetcode.editor.cn;

import utils.ListNode;


/**
 * 环形链表
 * @author qulq
 * @date 2024-09-17 16:26:42
 */
public class T141_LinkedListCycle{
	 public static void main(String[] args) {
	 	 // 测试代码
	 	 Solution solution = new T141_LinkedListCycle().new Solution();
	 }
	 
// 力扣代码
//leetcode submit region begin(Prohibit modification and deletion)
/**
 * Definition for singly-linked list.
 * class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode(int x) {
 *         val = x;
 *         next = null;
 *     }
 * }
 */
public class Solution {
    public boolean hasCycle(ListNode head) {
		if (head == null) {
			return false;
		}
		ListNode slow = head, fast = head;
		while (fast != null && fast.next != null) {
			slow = slow.next;
			fast = fast.next.next;
			if (slow == fast) {
				return true;
			}
		}
		return false;
    }
}
//leetcode submit region end(Prohibit modification and deletion)

}